package com.suarte.webapp.action;

import com.suarte.core.PaymentType;

import java.io.Serializable;
import org.appfuse.service.GenericManager;

/**
 * @date   Jan 04, 2011
 * @author Gcastillo
 */
public class PaymentTypeForm extends BasePage implements Serializable {
    private GenericManager<PaymentType, Long> paymentTypeManager;
    private PaymentType paymentType = new PaymentType();
    private Long id;

    public void setPaymentTypeManager(GenericManager<PaymentType, Long> paymentTypeManager) {
        this.paymentTypeManager = paymentTypeManager;
    }

    public PaymentType getPaymentType() {
        return paymentType;
    }

    public void setPaymentType(PaymentType paymentType) {
        this.paymentType = paymentType;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String delete() {
        paymentTypeManager.remove(paymentType.getId());
        addMessage("paymentType.deleted");

        return "list";
    }

    public String edit() {
        if (id != null) {
            paymentType = paymentTypeManager.get(id);
        } else {
            paymentType = new PaymentType();
        }

        return "edit";
    }

    public String save() {
        boolean isNew = (paymentType.getId() == null);
        paymentTypeManager.save(paymentType);

        String key = (isNew) ? "paymentType.added" : "paymentType.updated";
        addMessage(key);

        if (isNew) {
            return "list";
        } else {
            return "edit";
        }
    }
}